import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import menuModel from '@/model/menuModel'
import router from '@/router'
export const useUserStore = defineStore('user', () => {
  const accessToken = ref('')
  const refreshToken = ref('')
  const accessTokenTime = ref(0)
  const userInfo = ref()
  const defaultPath = ref(menuModel.menu[0].children[0].route)
  function clearUserInfo() {
    accessToken.value = ''
    refreshToken.value = ''
    accessTokenTime.value = 0
    userInfo.value = {}
    router.push({ name: "login" })
  }
  return { accessToken, refreshToken, accessTokenTime, userInfo, defaultPath, clearUserInfo }
},
  {
    persist: {
      key: "user",
      storage: localStorage
    }
  })
